layui.use(['layer', 'form', 'element', 'admin'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var element = layui.element;
    var admin = layui.admin;

    /* 选择头像 */
    $('#userInfoHead').click(function () {
        admin.cropImg({
            imgSrc: $('#userInfoHead>img').attr('src'),
            onCrop: function (res) {
                $('#userInfoHead>img').attr('src', res);
                parent.layui.jquery('.layui-layout-admin>.layui-header .layui-nav img.layui-nav-img').attr('src', res);
            }
        });
    });

    /* 监听表单提交 */
    form.on('submit(userInfoSubmit)', function (data) {
       // layer.msg(JSON.stringify(data.field));
        $.ajax({
            url: basePath + "/admin/userBase/save",
            type:"post",
            data: JSON.stringify(data.field),
            async: false,
            contentType: 'application/x-www-form-urlencoded',
            beforeSend:function(xhr){
                xhr.setRequestHeader("token", auth.token);
            },
            success: function (sResponse) {
                if(sResponse.code=="00000"){

                }else{
                   // layer.msg('登录失败', {icon: 2, anim: 6});
                }
            },
            error:function(a,b,c){
                layer.msg('登录失败【'+c+'】', {icon: 2, anim: 6});
            }
        });

        return false;
    });
/*
    getUserInfo();

    // 获取用户信息
    function getUserInfo(){
        $.ajax({
            type: "get",
            url: basePath + '/admin/users/query/'+auth.username,
            dataType: "json",
            //这里是重点
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("token", auth.token);
            },
            success: function (data) {
                if(data.code=="00000"){
                    let user=data.data;
                    console.log("===========>"+user);
                    form.val('userInfoForm', user);
                }
            },
            error:function(error){console.log(error);}
        });
    };

*/
});


